package com.suoluo.zenadmin.controllers.admin.weixin;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

import com.suoluo.zenadmin.http.weixin.Menu;
import com.suoluo.zenadmin.http.weixin.MenuButton;
import com.suoluo.zenadmin.http.weixin.MenuItem;
import com.suoluo.zenadmin.http.weixin.WXHttp;
import com.suoluo.zenadmin.http.weixin.WXHttpResult;

@Path("/")
public class WeiXinController {

	@Get("")
	public String createMenuView(Invocation inv){
		return "createMenu";
	}
	@Post("createmenu")
	public String createmenu(Invocation inv){
		String token = inv.getParameter("access_token");
		String bodys = inv.getParameter("body");
//		WXHttp http = new WXHttp();
		WXHttpResult result = WXHttp.createMenus(token, bodys);
//		WXHttpResult result = new WXHttpResult();
//		result.setErrmsg("Hello!!!");
		inv.addModel("result",result);
		return "createMenu";
	}
	@Get("query")
	public String queryMenuView(Invocation inv){
		return "queryMenu";
	}
	@Post("queryMenu")
	public String queryMenu(Invocation inv){
		String token = inv.getParameter("access_token");
//		WXHttp http = new WXHttp();
		//Menu menu = WXHttp.getMenus(token);
		//MenuButton menuButton = menu.getMenu();
		
		MenuButton menu = new MenuButton();
		MenuItem[] button = new MenuItem[3];
		MenuItem item1 = new MenuItem();
		item1.setType("click");
		item1.setName("今日歌曲");
		item1.setKey("V1001_TODAY_MUSIC");
		item1.setUrl("http://www.soso.com/");
		item1.setSub_button(null);
		button[0] = item1;
		MenuItem item2 = new MenuItem();
		item2.setType("click");
		item2.setName("歌手简介");
		item2.setKey("V1001_TODAY_SINGER");
		item2.setUrl("http://www.soso.com/");
		item2.setSub_button(null);
		button[1] = item2;
		
		MenuItem item3 = new MenuItem();
		button[2] = item3;
		item3.setName("菜单");
		MenuItem[] button1 = new MenuItem[3];
		MenuItem items1 = new MenuItem();
		items1.setType("view");
		items1.setName("搜索");
		items1.setUrl("http://www.soso.com/");
		button1[0] = items1;
		
		MenuItem items2 = new MenuItem();
		items2.setType("view");
		items2.setName("视频");
		items2.setUrl("http://v.qq.com/");
		items2.setSub_button(null);
		button1[1] = items2;
		
		MenuItem items3 = new MenuItem();
		items3.setType("click");
		items3.setName("赞一下我们");
		items3.setKey("V1001_GOOD");
		items3.setSub_button(null);
		button1[2] = items3;
		
		item3.setSub_button(button1);
		menu.setButton(button);
		//inv.addModel("menu",menu.getMenu());
		inv.addModel("menu",menu);
		return "menuInfo";
	}
	@Get("delete")
	public String deleteMenuView(Invocation inv){
		return "deleteMenu";
	}
	@Post("deletemenu")
	public String deleteMenu(Invocation inv) {
		String token = inv.getParameter("access_token");
//		WXHttp http = new WXHttp();
		WXHttpResult result = WXHttp.deleteMenus(token);
		inv.addModel("result",result);
		return "deleteMenu";
	}
}
